package cst.a305htr.recyclertest305htr.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.List;

import cst.a305htr.recyclertest305htr.bean.ArticleBean;
import cst.a305htr.recyclertest305htr.adapter.MyAdapter;
import cst.a305htr.recyclertest305htr.R;
import cst.a305htr.recyclertest305htr.iface.ArticleListen;
import cst.a305htr.recyclertest305htr.model.ArticleModel;;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity implements ArticleListen {
    private List<ArticleBean> list;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel articleModel= new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    private void initRecyclerView() {
        recyclerView=(RecyclerView)findViewById(R.id.recycleview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
  /*      list=getData();*/
        mAdapter=new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }

  /*  private List<ArticleBean> getData() {
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean art;

        art=new ArticleBean();
        art.setId(1);
        art.setName("标题1");
        art.setDescription("描述1");
        art.setThumb(R.drawable.f1);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        art=new ArticleBean();
        art.setId(2);
        art.setName("标题2");
        art.setDescription("描述2");
        art.setThumb(R.drawable.f2);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        art=new ArticleBean();
        art.setId(3);
        art.setName("标题3");
        art.setDescription("描述3");
        art.setThumb(R.drawable.f3);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        art=new ArticleBean();
        art.setId(4);
        art.setName("标题4");
        art.setDescription("描述4");
        art.setThumb(R.drawable.f4);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        art=new ArticleBean();
        art.setId(5);
        art.setName("标题5");
        art.setDescription("描述5");
        art.setThumb(R.drawable.f5);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        art=new ArticleBean();
        art.setId(6);
        art.setName("标题6");
        art.setDescription("描述6");
        art.setThumb(R.drawable.f6);
        art.setDescription("2017-5-12 15:16");
        list.add(art);

        return list;
    }*/

    @Override
    public void OnResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void OnFail(String msg) {
        Toast.makeText(this, "fail"+msg, Toast.LENGTH_SHORT).show();
    }
}
